package com.xmhu2009.applications.entity.enums;

import org.springframework.util.StringUtils;

import com.fasterxml.jackson.annotation.JsonValue;
import com.xmhu2009.common.mybatis.EnumCodeGetter;
import com.xmhu2009.common.mybatis.EnumDescriptionGetter;

public enum UserStatus implements EnumCodeGetter, EnumDescriptionGetter {
    INIT("0", "初始化"),
    NORMAL("1", "正常"),
    LOCKED("2", "锁定"),
    DELETED("9", "已删除");

    private String code;

    private String description;

    UserStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    @JsonValue
    public String getCode() {
        return code;
    }

    public static UserStatus getEnumByCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        for (UserStatus element : UserStatus.values()) {
            if (code.equals(element.getCode())) {
                return element;
            }
        }
        return null;
    }
}
